import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login/Login.vue";
import mainRouter from "@/router/mainRouter";
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: Login,
    name: "Login",
  },
  {
    path: "/",
    redirect: "/login",
  },
];
// 重写路由的容错
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((error) => error);
};

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes: routes,
});
var _routes = JSON.parse(sessionStorage.getItem("menus")) || [];
mainRouter(_routes, router);
export default router;
